package com.wxapp.dispatch.service.job.openfeign;

import com.wxapp.common.base.util.bean.SpringUtils;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.FeignRequestVo;
import com.wxapp.common.util.feign.DynamicFeignUtil;
import com.wxapp.dispatch.api.pojo.vo.dispatch.QDispatchVo;
import com.wxapp.dispatch.service.job.BaseJob;
import lombok.NoArgsConstructor;
import org.quartz.JobExecutionContext;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;

@Component(value = "OpenFenginJob")
@NoArgsConstructor
public class OpenFeignJob extends BaseJob {
    @Override
    protected ResultVm<Object> toDealJob(JobExecutionContext context, QDispatchVo dispatchVm) {
       var dynamicClientService= SpringUtils.getBean(DynamicFeignUtil.class);
        HttpMethod httpMethod;
        //请求
        switch (dispatchVm.getType().getValue()) {
            case "POST"-> httpMethod= HttpMethod.POST;
            case "DELETE"-> httpMethod= HttpMethod.DELETE;
            case "PUT"->  httpMethod= HttpMethod.PUT;
            default->httpMethod= HttpMethod.GET;
        }
        return dynamicClientService.executeApi(new FeignRequestVo<>(dispatchVm.getSysName(), dispatchVm.getUrl(), dispatchVm.getToken(), dispatchVm.getParam(),httpMethod));
    }
}